package at.fhooe.mc.master.clc.client.view;

import java.util.Date;
import java.util.Set;

import at.fhooe.mc.master.clc.client.presenter.MetricsRequestPresenter.IMetricsRequestView;
import at.fhooe.mc.master.clc.client.widget.CheckBoxTable;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.logical.shared.OpenEvent;
import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;

public class MetricsRequestView extends Composite implements IMetricsRequestView
{
	private DisclosurePanel panel = new DisclosurePanel("Metrics Data Request");
	
	private FlexTable table = new FlexTable();
	
	private IsWidget frameworkListWidget;
	private IsWidget metricsListWidget;
	
	private Button btnRequestGraph;
	
	private FlexTable datePickTable;
	
	private VerticalPanel manualDatePanel;
	private DateBox startDate;
	private DateBox endDate;
	
	private boolean selectByInterval = true;
	
	public MetricsRequestView()
	{
		table.getFlexCellFormatter().setColSpan(0, 0, 2);
		
		manualDatePanel = new VerticalPanel();
		Label startDateLabel = new Label("Start Date: ");
		startDate = new DateBox();
		Label endDateLable = new Label("End Date: ");
		endDate = new DateBox();
		manualDatePanel.add(startDateLabel);
		manualDatePanel.add(startDate);
		manualDatePanel.add(endDateLable);
		manualDatePanel.add(endDate);
		
		datePickTable = new FlexTable();
		datePickTable.setWidget(0, 0, manualDatePanel);
		
		// set this as the startup widget...
		VerticalPanel requestPanel = new VerticalPanel();
		
		btnRequestGraph = new Button("Request Graph(s)");
		
		//requestPanel.add(chkCombineValuesInGraph);
		requestPanel.add(btnRequestGraph);
		
		// TODO Add the widgets above to the table
		table.setWidget(0, 0, datePickTable);
		table.setWidget(0, 1, new Image("/img/ajax-loader.gif"));
		table.setWidget(0, 2, new Image("/img/ajax-loader.gif"));
//		table.setWidget(0, 3, new Image("/img/ajax-loader.gif"));
//		table.setWidget(0, 4, new Image("/img/ajax-loader.gif"));
		table.setWidget(0, 5, requestPanel);
		
		panel.add(table);
		panel.setOpen(true);
		
		initWidget(panel);
	}
	
	@Override
	public DisclosurePanel getCollapsiblePanel()
	{
		return this.panel;
	}
	
	@Override
	public void setFrameworkListWidget(IsWidget widget)
	{
		CaptionPanel cp = new CaptionPanel("Select Framework(s)");
		cp.add(widget);
		this.frameworkListWidget = widget;
		table.setWidget(0, 1, cp);
		
	}

	@Override
	public void setMetricListWidget(IsWidget widget)
	{
		CaptionPanel cp = new CaptionPanel("Select Metric(s)");
		cp.add(widget);
		this.metricsListWidget = widget;
		table.setWidget(0, 2, cp);
	}

	@Override
	public Set<Integer> getSelectedFrameworkIndexes()
	{
		return ((CheckBoxTable)this.frameworkListWidget).getSelectedRows();
	}

	@Override
	public Set<Integer> getSelectedMetricsIndexes()
	{
		return ((CheckBoxTable)this.metricsListWidget).getSelectedRows();
	}

	@Override
	public Date getStartDate()
	{
		return startDate.getValue();
	}

	@Override
	public Date getEndDate()
	{
		return endDate.getValue();
	}

	@Override
	public Button getCreateGraphButton()
	{
		return btnRequestGraph;
	}

}
